<?php

use yii\db\Migration;

class m171127_020745_alter_classroom_group extends Migration
{
    private function createDbs(){
        $dbs = [];
        $dbs_info =\Yii::$app->params['db'];
        foreach($dbs_info as $k=>$v){
            $dbs[$k] = \Yii::createObject($v);
        }
        return $dbs;
    }
    public function safeUp()
    {
        $dbs = $this->createDbs();
        foreach ($dbs as $v) {
            $this->db = $v;
            $this->addColumn('{{%classroom_group}}', 'effective', $this->smallInteger(4)->defaultValue(0)->comment('有效教室'));
            $this->addColumn('{{%classroom_group_relation}}', 'classroom_attr_id', $this->integer()->defaultValue(0)->comment('上课时间id'));
        }

    }

    public function safeDown()
    {
        $dbs = $this->createDbs();
        foreach ($dbs as $v) {
            $this->db = $v;
            $this->dropColumn('{{%classroom_group}}', 'effective');
            $this->dropColumn('{{%classroom_group_relation}}', 'classroom_attr_id');
        }
    }
}
